package cn.learn.httpclient;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author huangyezhan
 * @version 1.0
 * @date 2021年08月30日17:21
 */
@RestController
public class HttpClient1Controller {


    @RequestMapping(value = "/http1", method = RequestMethod.GET)
    public String testAsync() {
        Map<String, String> map = new HashMap<>();
        map.put("msg",msg);
        String              s1  = JSONObject.toJSONString(map);
        String              s   = HttpClientUtil.INSTANCE.doPost("http://localhost:8009/http2", s1);
        return s;
    }

    private String msg = "{\"what\":21,\"arg1\":0,\"object\":{\"parentId\":\"682f601b-0b9c-4a5b-b1c3-4fa7de5b19b4\",\"objectId\":\"6daf60e0-6649-4cf5-a560-d0dc6518f7e6\",\"objectType\":\"Thing\",\"name\":\"DZlW0NbvDbOhJ5pK7VBc\",\"srn\":\"srn::iot::Thing/scbusiness/fresh-cabinet/DZlW0NbvDbOhJ5pK7VBc\"},\"eventTime\":\"2021-08-23T16:40:27.780771597+08:00\",\"data\":{\"eventTime\":\"2021-08-23T16:40:27.780771597+08:00\",\"eventName\":\"doorClose\",\"data\":{\"closeDoorTime\":\"2021-08-23T16:40:27.780771597+08:00\",\"closeDoorWeight\":[{\"changed\":0,\"channelId\":101,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.283130214+08:00\",\"weight\":10780},{\"changed\":0,\"channelId\":102,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.311898175+08:00\",\"weight\":8956},{\"changed\":0,\"channelId\":103,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.340853678+08:00\",\"weight\":-14},{\"changed\":0,\"channelId\":104,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.369972806+08:00\",\"weight\":9184},{\"changed\":0,\"channelId\":105,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.398722684+08:00\",\"weight\":16588},{\"changed\":0,\"channelId\":201,\"goodsId\":\"1415559846658232322\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.427040895+08:00\",\"weight\":2318},{\"changed\":-258,\"channelId\":202,\"goodsId\":\"1415559846658232322\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.455950023+08:00\",\"weight\":2084},{\"changed\":0,\"channelId\":203,\"goodsId\":\"1369574038826864642\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.484973776+08:00\",\"weight\":534},{\"changed\":0,\"channelId\":204,\"goodsId\":\"1369574038826864642\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.513393779+08:00\",\"weight\":3298},{\"changed\":0,\"channelId\":205,\"goodsId\":\"1393086577648771073\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:27.541194031+08:00\",\"weight\":3772}],\"doorId\":2,\"err\":\"\",\"errCode\":0,\"openDoorTime\":\"2021-08-23T16:40:18.218395845+08:00\",\"openDoorWeight\":[{\"changed\":0,\"channelId\":101,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:17.801988469+08:00\",\"weight\":10780},{\"changed\":0,\"channelId\":102,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:17.831207347+08:00\",\"weight\":8956},{\"changed\":0,\"channelId\":103,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:17.8598496+08:00\",\"weight\":-14},{\"changed\":0,\"channelId\":104,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:17.88905477+08:00\",\"weight\":9184},{\"changed\":0,\"channelId\":105,\"goodsId\":\"1369573561708007426\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:17.918460898+08:00\",\"weight\":16588},{\"changed\":0,\"channelId\":201,\"goodsId\":\"1415559846658232322\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:17.947704859+08:00\",\"weight\":2318},{\"changed\":0,\"channelId\":202,\"goodsId\":\"1415559846658232322\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:17.977293862+08:00\",\"weight\":2342},{\"changed\":0,\"channelId\":203,\"goodsId\":\"1369574038826864642\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:18.006009698+08:00\",\"weight\":534},{\"changed\":0,\"channelId\":204,\"goodsId\":\"1369574038826864642\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:18.033784826+08:00\",\"weight\":3298},{\"changed\":0,\"channelId\":205,\"goodsId\":\"1393086577648771073\",\"relativeChanged\":0,\"simplingTime\":\"2021-08-23T16:40:18.062692787+08:00\",\"weight\":3770}],\"operate\":\"BUY\",\"operateSN\":\"1429725141165613057\",\"userId\":\"oLGL_47Yudv6vRwixluq2LOriitU\"}}}";

}

@RestController
class HttpClient2Controller {
    @RequestMapping(value = "/http2", method = RequestMethod.POST)
    public String testAsync(@RequestBody String msg) {
        System.out.println("-------------------");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(msg);
        return "success";
    }

}
